<?php require_once(dirname(__FILE__)."/../config/config.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php  
if($_SESSION['admin_name']=="")
{

	echo "<script>location.href='admin_login.php';</script>";
}
?>
<?php  
function upload_image($imgpath)
     {
       $name=$imgpath["name"];
       $tmp_name=$imgpath["tmp_name"];
	$filetype = pathinfo($name, PATHINFO_EXTENSION);//获取后缀
       $size=$imgpath["size"];
	   $filename=date("YmdHis",time()).rand(1000,9999).".".$filetype;
	   $filepath="/userfiles/gift/".$filename;
       $uploadfile = "../userfiles/gift/".$filename;
     
	 
    if(move_uploaded_file($tmp_name,$uploadfile))
         return $filepath; 
  }
 ?>
 <?
 if($_FILES['image']['size']>0){
 	  $image=$_FILES['image'];
	$image=upload_image($image);
 }else{
 	$image=$_REQUEST['xiaotu'];
 }
  if($_FILES['image2']['size']>0){
	 $image2=$_FILES['image2'];
	 $image2=upload_image($image2);
 }else{
 	$image2=$_REQUEST['xiaotu2'];
 }
?>
 <?php
     switch($_GET["action"]){
	 	case "add":
	
if($_POST['gift_name']!=""&&$_POST['integral']!=""&&$image!=""&&$image2!=""&&$_POST['description']!="")
{
	
		$sql="INSERT INTO zy_gift ( gift_name,integral, image,image2,description)
VALUES
('$_POST[gift_name]','$_POST[integral]','$image','$image2','$_POST[description]') ";

   mysql_query($sql);
$gift_id=mysql_insert_id($myconn);
	
	echo "<h3>礼品信息发送成功!</h3>";
	echo "<a href='gift.php'>浏览礼品信息</a>  ";
 
  echo "<a href='gift_add.php'>返回</a>&nbsp;&nbsp;";

}else{
	echo "<script>alert('不能为空，请如实填写')</script>";
	echo "<script>location.href='gift_add.php';</script>";
}
	
/*if($gift_id>0)
{
echo "<h3>礼品信息发布成功!</h3>";
}else
{ echo "<h3>礼品信息发布失败!</h3>";}*/
 		break;
		case  "del":
	$gift_id = $_GET['gift_id'];
	$page=$_REQUEST['page'];
	$sql = "delete from zy_gift where gift_id = '".$gift_id."'";
	mysql_query($sql);
	header("location:gift.php?page=".$page);
	break;
	case "update":
	$gift_name = $_POST["gift_name"];
	$integral = $_POST["integral"];
	$description=$_POST['description'];
	$gift_id=$_GET['gift_id'];
	$page=$_REQUEST['page'];
	$sql = "update zy_gift set  gift_name='".$gift_name."', integral='".$integral."',image = '".$image."',image2='".$image2."',description='".$description."' where   gift_id ='".$gift_id."'";
   // echo $sql;
	mysql_query($sql);
	header("location:gift.php?page=".$page);
	break;
}
?>
</body>
</html>